/**
 * 
 */
package com.and.xmppsdk.adapter;

import java.util.List;

import org.drl.xmpp.Contact;
import org.drl.xmpp.util.StringHelper;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.and.xmppsdk.R;

/**
 * @author Administrator
 * 
 */
public class ContactAdapter extends ArrayAdapter<Contact> {
	private LayoutInflater mInflater;

	/**
	 * @param context
	 * @param c
	 */
	public ContactAdapter(Context context, List<Contact> lst) {
		super(context, 0, lst);
		mInflater = LayoutInflater.from(context);
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		if (view == null) {
			view = mInflater
					.inflate(R.layout.adapter_contact_01, parent, false);
		}
		Contact mCm = getItem(position);
		setupContactViewItem(view, mCm);
		return view;
	}

	public static final  void setupContactViewItem(View view, Contact mCm) {
		if(view==null || mCm ==null){
			return ;
		}
		TextView name1 = (TextView) view.findViewById(R.id.name);
		TextView name2 = (TextView) view.findViewById(R.id.name2);
		TextView status = (TextView) view.findViewById(R.id.status);
		name1.setText(mCm.getName());
		
		if(StringHelper.isText(mCm.getJID())){
			name2.setText(mCm.getJID());
		}
		status.setText(mCm.getStatusText());
	}

}
